<?php

/**
 * @file
 * Default simple view template to all the fields as a row.
 *
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->wrapper_prefix: A complete wrapper containing the inline_html to use.
 *   - $field->wrapper_suffix: The closing tag for the wrapper.
 *   - $field->separator: an optional separator that may appear before a field.
 *   - $field->label: The wrap label text to use.
 *   - $field->label_html: The full HTML of the label to use including
 *     configured element type.
 * - $row: The raw result object from the query, with all data it fetched.
 *
 * @ingroup views_templates
 */
?>
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
	<?php print $field->separator; ?>
  <?php endif; ?>

<?php 

  if($field->label == '评论')  
	{
		print $field->wrapper_prefix;
		$field->label_html = str_replace($field->label_html,'评论','<i></i>评论');
		print $field->label_html;
		print $field->content;
		
		$qid = get_node_quizzler_id($row->nid);
		if($qid > 0) {
			$attempts = quizzler_attempts($qid); 
			print '<span class="views-label views-label-quiz-attempts"><i></i>测验</span><span class="field-content">('.$attempts.')</span>';
		}
		
		print $field->wrapper_suffix;
	} 
	else if($field->label == '内容') 
	{		  
		$tags_query = db_select('taxonomy_index','ti');
		$tags_query->join('taxonomy_term_data','td','ti.tid = td.tid AND td.vid = :vid',array(':vid' => 3));
		$tags_query->join('node','n','n.nid = ti.tid');
		$tags_query->fields('ti',array('tid'))
				 ->fields('n',array('nid','title'))
				 ->condition('n.nid',$row->nid,'<>')
				 ->condition('n.type','article')
				 ->orderby('n.nid','DESC');
		$tags_result = $tags_query->execute();
		
		if($tags_result->rowCount()!=0){
			$count = 0;
			$output_title = '<div class="related_articles"><ul>';
			foreach ($tags_result as $record){
				if($count++<3){
					$output_title .= '<li><a href='.base_path().'?q=node/'.$record->nid.'>'.$record->title.'</a></li>';
				}
				}
			$output_title .= '</ul></div>';
		}
		print $field->wrapper_prefix;
	  print $field->label_html;
	  print $field->content;
	  print $output_title;
	  print $field->wrapper_suffix;
	} 
	else 
	{
		print $field->wrapper_prefix;
		print $field->label_html;
		print $field->content;
		print $field->wrapper_suffix;
	}
	?>
<?php endforeach; ?>